//
//  WJYRadioPlayerTableViewCell.m
//  WWLNetease
//
//  Created by dllo on 15/12/29.
//  Copyright © 2015年 Echo.Jobs. All rights reserved.
//

#import "WJYRadioPlayerTableViewCell.h"

@interface WJYRadioPlayerTableViewCell()

@property (nonatomic, retain) UIImageView *image;/**<图片*/
@property (nonatomic, retain) UILabel *titleLable;
@property (nonatomic, retain) UILabel *sizeLable;
@property (nonatomic, retain) UILabel *timeLable;
@property (nonatomic, retain) UIImageView *musicV;
@end

@implementation WJYRadioPlayerTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createView];
    }
    return self;
}



#pragma mark- 创建View
- (void)createView
{
    // 标题
    self.titleLable = [[UILabel alloc]init];
    [self addSubview:self.titleLable];
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@15);
        make.left.equalTo(@30);
        make.right.equalTo(@-50);
        make.height.equalTo(@10);
        
    }];
    self.titleLable.font = [UIFont systemFontOfSize:16 * SIZE];
    
    self.musicV = [[UIImageView alloc]init];
    [self addSubview:self.musicV];
    [self.musicV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(5);
        make.right.equalTo(self.titleLable.mas_left);
        make.top.equalTo(self.titleLable.mas_top).offset(-10);
        make.height.equalTo(@25);
        
    }];
//    self.musicV.backgroundColor = [UIColor redColor];
    
    
    
    self.sizeLable = [[UILabel alloc]init];
    [self addSubview:self.sizeLable];
    [self.sizeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLable.mas_bottom).offset(15);
        make.left.equalTo(self.titleLable).offset(3);
        make.width.equalTo(@50);
        make.height.equalTo(@10);
        
    }];
    self.sizeLable.font = [UIFont systemFontOfSize:13.5 * SIZE];
    self.sizeLable.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    
    self.timeLable = [[UILabel alloc]init];
    [self addSubview:self.timeLable];
    [self.timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-10);
        make.width.equalTo(@100);
        make.top.bottom.equalTo(self.sizeLable);
        
    }];
    self.timeLable.textAlignment = NSTextAlignmentRight;
    self.timeLable.font = [UIFont systemFontOfSize:13.5 * SIZE];
    self.timeLable.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
}

- (void)setPlayerModel:(WJYRadioPlayerModel *)playerModel{
    // 标题
    self.titleLable.text = [NSString stringWithFormat:@"%@",playerModel.title];
    self.sizeLable.text = playerModel.size;
    
//    NSDate *date = [NSDate date];
//    NSTimeZone *zone = [NSTimeZone systemTimeZone];
//    NSInteger interval = [zone secondsFromGMTForDate: date];
//    NSDate *localeDate = [date  dateByAddingTimeInterval: interval];
    NSDate *date = [NSDate date];
    NSDateFormatter *f = [[NSDateFormatter alloc]init];
    f.dateFormat = @"yyyy-MM-dd";
    NSString *sysDateStr = [f stringFromDate:date];
    NSString *pTimeStr  = [playerModel.ptime substringToIndex:10];
//    NSLog(@"------------%@", playerModel.ptime);
//    NSLog(@"系统时间-----%@", [NSDate date]);
    
    
    if ([pTimeStr isEqualToString:sysDateStr]) {
        f.dateFormat = @"yyyy-MM-dd hh-mm-ss";
        NSString *sysDateStr = [f stringFromDate:date];
        sysDateStr = [sysDateStr substringWithRange:NSMakeRange(11, 2)];
        NSString *pTimeStr  = [playerModel.ptime substringWithRange:NSMakeRange(11, 2)];
        
        NSLog(@"%ld--------%ld", pTimeStr.integerValue, sysDateStr.integerValue);

        self.timeLable.text = [NSString stringWithFormat:@"%ld小时前", sysDateStr.integerValue + 12 - pTimeStr.integerValue];

    }else{
        self.timeLable.text = pTimeStr;
        
    }
    
    
   
    self.musicV.image = [UIImage imageNamed:@"iconfont-yinle.png"];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
